/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package stis.statpro.ibs.widget;

import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.RenderingHints;
import java.awt.event.MouseAdapter;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JButton;

/**
 *
 * @author habib <imamhabibpamungkas@gmail.com>
 */
public class WidgetButton extends JButton {

    private boolean enter;
    private boolean press;
    
    public boolean isEnter() {
        return enter;
    }

    public void setEnter(boolean enter) {
        this.enter = enter;
    }

    public boolean isPress() {
        return press;
    }

    public void setPress(boolean press) {
        this.press = press;
    }

    
    public WidgetButton() {
        setBorderPainted(false);
        setFocusPainted(false);
        setContentAreaFilled(false);
        addMouseListener(new MouseAdapter() {

            @Override
            public void mouseEntered(java.awt.event.MouseEvent e) {
                super.mouseEntered(e); //To change body of generated methods, choose Tools | Templates.
                setEnter(true);
                repaint();
            }

            @Override
            public void mouseExited(java.awt.event.MouseEvent e) {
                super.mouseExited(e); //To change body of generated methods, choose Tools | Templates.
                setEnter(false);
                repaint();
            }

            @Override
            public void mousePressed(java.awt.event.MouseEvent e) {
                super.mousePressed(e); //To change body of generated methods, choose Tools | Templates.
                setPress(true);
                repaint();
            }

            @Override
            public void mouseReleased(java.awt.event.MouseEvent e) {
                super.mouseReleased(e); //To change body of generated methods, choose Tools | Templates.
                setPress(false);
                repaint();
            }
        });
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g); //To change body of generated methods, choose Tools | Templates.
        GradientPaint paint;
        RoundRectangle2D rrd=rrd = new RoundRectangle2D.Double(0, 0,getWidth(), getHeight(), 10, 10);
        if (this.enter) {
            if (this.press) {
                paint = new GradientPaint(new Point(0, 0), new Color(0.000f, 0.000f, 0.502f,0.7f), new Point(0, getHeight()),new Color(0f, 0f, 0f,0.3f));
                rrd = new RoundRectangle2D.Double(0, 0,getWidth(), getHeight(), 5, 5);
            } else {
                paint = new GradientPaint(new Point(0, 0), new Color(0.867f, 0.627f, 0.867f,0.3f), new Point(0, getHeight()), new Color(0.294f, 0.000f, 0.510f,0.7f));
                rrd = new RoundRectangle2D.Double(0, 0,getWidth(), getHeight(), 10, 10);
            }

        } else {
            paint = new GradientPaint(new Point(0, 0),new Color(0f, 0f, 0f,0.7f), new Point(0, getHeight()/2),new Color(0.502f, 0.502f, 0.502f,0.3f));
        }
        
        Graphics2D gd = (Graphics2D) g.create();
        gd.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        gd.setPaint(paint);
        gd.fill(rrd);
        gd.dispose();
    }
 
    
}
